unit Skins;

interface

uses
  Database,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, FileCtrl, MMSystem, ExtCtrls;

type
  TFormSkins = class(TForm)
    BtnOK: TBitBtn;
    BtnCancel: TBitBtn;
    Label2: TLabel;
    DL: TDirectoryListBox;
    ListSkins: TListBox;
    Memo: TMemo;
    LabelDescription: TLabel;
    BtnDownload: TBitBtn;
    procedure BtnCancelClick(Sender: TObject);
    procedure BtnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ListSkinsKeyPress(Sender: TObject; var Key: Char);
    procedure ListSkinsClick(Sender: TObject);
    procedure BtnDownloadClick(Sender: TObject);
  private
    { Private declarations }
    procedure UpdateMemo;
  public
    { Public declarations }
    doload: boolean;
  end;

var
  FormSkins: TFormSkins;

implementation

{$R *.DFM}

procedure TFormSkins.FormCreate(Sender: TObject);
var
  i: integer;
  ready: boolean;
begin
  doload:=false;
  DL.directory:=Datawell.exedir+'\skins';
  ready:=false;
  for i:=0 to DL.items.count-1 do begin
    if not ready then begin
      if lowercase(DL.items[i]) = 'skins' then ready:=true;
      continue;
    end;
    if not fileexists(Datawell.exedir+'\skins\'+DL.items[i]+'\config.txt') then continue;
    ListSkins.items.add(DL.items[i]);
  end;
end;

procedure TFormSkins.ListSkinsClick(Sender: TObject);
begin
  UpdateMemo;
end;

procedure TFormSkins.ListSkinsKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    key:=#0;
    BtnOK.click;
  end;
end;

procedure TFormSkins.BtnCancelClick(Sender: TObject);
begin
  close;
end;

procedure TFormSkins.BtnOKClick(Sender: TObject);
var skin: string;
begin
  if ListSkins.itemindex < 0 then begin
    messagedlg('No skin selected',mtinformation,[mbok],0);
    exit;
  end;
  skin:=ListSkins.items[ListSkins.itemindex];
  Datawell.TableGlobals.edit;
  Datawell.TableGlobals.fieldbyname('S23').asstring:=skin;
  Datawell.TableGlobals.post;
  doload:=true;
  close;
end;

procedure TFormSkins.UpdateMemo;
var
  i: integer;
  skin, work: string;
  lines: TStringList;
begin
  Memo.lines.clear;
  if ListSkins.itemindex < 0 then exit;
  skin:=Datawell.exedir+'\skins\'+ListSkins.items[ListSkins.itemindex]+'\config.txt';
  if not fileexists(skin) then exit;
  lines:=TStringList.create;
  if fileExists(skin) then
    lines.loadfromfile(skin);
  if lines.count < 1 then exit;
  for i:=0 to lines.count-1 do begin
    work:=lines[i];
    if copy(work,1,1) <> '!' then continue;
    Memo.lines.add(copy(work,2,9999));
  end;
  if Memo.lines.count < 1 then Memo.lines.add('<No description available>');
end;

procedure TFormSkins.BtnDownloadClick(Sender: TObject);
begin
  Datawell.EXE('http://www.'+Datawell.homesite+'.com/reframe.php?target=skins.html','','c:\',SW_SHOW);
end;

end.

